<?php
session_start();
if(isset($_REQUEST['username'])){
	$password=$_REQUEST['password'];
	$password2=sha1($password);
	
	include_once 'dbcofig.php';
	$statement="select * from teacheruser where username1=? and password=?";
	$pdoStatement = $pdo->prepare($statement);
	$input = array($_REQUEST['username'],trim($password2));
	$res=$pdoStatement->execute($input);
	if($res){
		$data=$pdoStatement->fetch();
		if($data){
			$_SESSION['username']=$_REQUEST['username'];
			header("location:table.php");
		}else {
			echo "用户名密码错，请重试！<a href='login.php'>回到登录页</a>";
		}
	}else {
		echo "系统内部错，请重试！<a href='login.php'>回到登录页</a>";
		exit();
	}
}else{
	if (isset($_SESSION['username'])){
		header("location:index.php");
	}else{
		header("location:login.php");
	}
}
?>